//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    mallList: {},
    is_check: false, //用于点击时切换点击元素的css样式
    motto: 'Hello',
    userInfo: {},
    page: '',
    height: '', // 手机屏幕高度
    imageWidth: wx.getSystemInfoSync().windowWidth,//swiper图片宽度
    navigateWidth: (wx.getSystemInfoSync().windowWidth-3)/4,//导航条宽度
    imgUrls: [
      '../image/1.jpg',
      '../image/1.jpg',
      '../image/1.jpg'
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
    loadingHidden:false,
  },
  changeIndicatorDots: function (e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    })
  },
  //点击跳转
  clickUrl: function(e){
    var that = this;
    var url = e.target.dataset.url;
    that.setData({
      is_check: true
    })
    wx.switchTab({
      url: url,
      success: function(res){
        that.setData({
          is_check: false
        })
      },
      fail: function(){
        console.log('网络错误');
      }
    })
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    var that = this;
    wx.getSystemInfo({
      success: function(res) {
        console.log(res.windowHeight)
        that.setData({
          height: res.windowHeight+500
        })
      },
    })
    this.getDataList('newlist');
  },
  /*
  * 滚动到底部时加载下一页
  */
  bindscrolltolower: function () {
    console.log('到底部')
  },
  /**
   * 加载数据
   */
  getDataList: function(a){
    var that=this;
    wx.request({
      url: 'https://cnodejs.org/api/v1/topics',
      data: {
        page: this.data.page,
        limit: '31',
        mdernder: false
      },
      header: {
        'contype-type': 'application/json'
      },
      success: function (res) {
        console.log(res.data)
        that.setData({
          mallList: res.data.data,
          loadingHidden: true,
          page: that.page+1
        })
      },
      fail: function () {
        console.log('请求失败')
      }
    })
  }
  
})
